# -*- coding: utf-8 -*-
# @Time    : 2022/5/24 9:54
# @Author  : zhangping
# @Email   : 2432115515@qq.com
# @File    : page_index.py
# @Software: PyCharm
from time import sleep
from selenium.webdriver.common.by import By
from page.base_page import BasePage
'''首页page'''
class IndexPage(BasePage):
        # 找到跳转首页的按钮
    ele_homepage_btn_locator = (By.XPATH, '/html/body/div[4]/div/div/a[1]')
        # 找到查看购物车的按钮
    ele_check_shopping_locator = (By.LINK_TEXT,'查看购物车')
        # 点击商品文字加入购物车
    ele_goods_link_locator = (By.XPATH, '/html/body/div[9]/div[3]/div[1]/div/ul[1]/li[2]/p/a')
        # 找到点击商品图片
    ele_goods_img_locator = (By.LINK_TEXT, '高质感毛呢大衣')
       # 输入缺货商品定位器
    ele_index_keyword_locator = (By.ID, "keyword")
    # 搜索定位器
    ele_index_search_btn_locator = (By.NAME, "imageField")


    # 找到搜索输入框元素
    ele_search_locator = (By.ID,'keyword')
    # 找到搜索按钮
    ele_search_btn_locator = (By.NAME,'imageField')
    # 找到我的账户
    ele_my_account_locator = (By.XPATH,'/html/body/div[1]/div/div/a[1]')

    def current_url(self):
        """获取当前地址"""
        return self.driver.current_url

    def home_page_btn(self):
        """点击首页"""
        self.driver.find_element(*self.ele_homepage_btn_locator).click()

    def look_shoppingcart(self):
        """点击查看购物车"""
        self.driver.find_element(*self.ele_check_shopping_locator).click()

    def goods_link(self):
        """点击商品链接"""
        self.driver.find_element(*self.ele_goods_link_locator).click()
        sleep(2)

    def goods_photo(self):
        """找到点击商品图片点击"""
        self.driver.find_element(*self.ele_goods_img_locator).click()
    def goods_stockout(self):
        """输入缺货商品"""
        self.driver.find_element(*self.ele_index_keyword_locator).send_keys("缺货商品")
    def goods_search(self):
        """点击搜索"""
        self.driver.find_element(*self.ele_index_search_btn_locator).click()
    def goods_input_search(self):
        """聚合提交商品缺货登记"""
        self.goods_stockout()
        self.goods_search()
    def Index_search(self):
        """搜索商品"""
        self.driver.find_element(*self.ele_search_locator).send_keys('毛貂')
        self.driver.find_element(*self.ele_search_btn_locator).click()
    def my_account(self):
        """点击我的账户"""
        self.driver.find_element(*self.ele_my_account_locator).click()



